//
//  YNUserGroupRelation.h
//  Messenger
//
//  Created by OC on 15/1/19.
//  Copyright (c) 2015年 李健. All rights reserved.
//
//  用户与群/讨论组关系实体类 groupType:1 群  groupType:2 讨论组
//

#import <Foundation/Foundation.h>
#import "YNIMFrameworkTypedef.h"

@interface YNContactGroupRelation : NSObject

//userNo用户ID
@property (nonatomic, strong) NSString *userNo;

//群ID
@property (nonatomic, strong) NSString *groupName;

//role 群成员类型
@property (nonatomic, strong) NSString *role;


//创建用户与群/讨论组关系表
+ (BOOL)createWithGroupDatabase:(FMDatabase *)db;

//插入用户与群/讨论组关系
- (BOOL)insertWithGroupDatabase:(FMDatabase *)db;

//更新用户与群/讨论组关系
- (BOOL)updateWithGroupDatabase:(FMDatabase *)db;

//删除表中指定群类型所有数据
+ (BOOL)deleteAllDataWithGroupType:(CurrenChatObjType)groupType database:(FMDatabase *)db;

//查询ContactGroupRelation是否存在
- (BOOL)isContactGroupRelExistInDatabase:(FMDatabase *)db;

//删除群/讨论组所有成员关系
+ (BOOL)deleteByGroupName:(NSString *)groupName database:(FMDatabase *)db;

//根据gruoupName查询用户
+ (NSArray *)queryByGruoupName:(NSString *)groupName database:(FMDatabase *)db isAdmin:(BOOL)isAdmin onlyGetTeachers:(BOOL)onlyTeacher;

//根据gruoupName查询用户的在线人数
+(NSInteger)queryUserOnlineCountByGruoupName:(NSString *)groupName database:(FMDatabase *)db isAdmin:(BOOL)isAdmin onlyGetTeachers:(BOOL)onlyTeacher;

//删除某个成员与群/讨论组关系
+ (BOOL)deleteByGroupName:(NSString *)groupName andUserNo:(NSString *)userNo database:(FMDatabase *)db;

//查询讨论组创建者，返回userId
+ (NSArray<NSString*> *)queryCreatorOfDiscussionGroupInDatabase:(FMDatabase *)db;

/**
 查询自己在群组里的角色（是否是管理员）
 
 @param groupType
 @param db
 @return 结果集
 */
+ (NSArray<NSDictionary*> *)queryMyGroupRoleWithGroupId:(NSString*)groupId database:(FMDatabase *)db;
@end
